package com.graduate.after.web.control;

import com.graduate.after.bean.CategoryDetailInfo;
import com.graduate.after.bean.CategoryInfo;
import com.graduate.after.constants.StatusCode;
import com.graduate.after.service.CategoryInfoService;
import com.graduate.after.utils.Result;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryInfoControl {

    @Autowired
    private CategoryInfoService categoryInfoService;

    @RequestMapping("/stair")
    public Result selectAllStairCategory() {
        List<CategoryInfo> categoryInfos = categoryInfoService.selectAllStairCategory();

        return Result.success(categoryInfos);
    }

    @RequestMapping("/second")
    public Result selectSecondByParentId(String parentId) {
        if(StringUtils.isBlank(parentId)) {
            return Result.fail(StatusCode.PARAM_IS_BLANK);
        }
        List<CategoryInfo> categoryInfos = categoryInfoService.selectSecondByParentId(Integer.parseInt(parentId));

        return Result.success(categoryInfos);
    }

    @RequestMapping("/detail")
    public Result selectDetailDataByCityId(String cityId) {
        if(StringUtils.isBlank(cityId)) {
            return Result.fail(StatusCode.PARAM_IS_BLANK);
        }
        List<CategoryDetailInfo> categoryDetailInfos = categoryInfoService.selectCategoryDetailInfo(Long.parseLong(cityId));
        
        return Result.success(categoryDetailInfos);
    }
}
